import { query } from '../db'

export interface Category {
  id: number
  name: string
  description: string
  status: number
}

// 获取所有分类
export async function getAllCategories(): Promise<Category[]> {
  const sql = 'SELECT * FROM blog_categories WHERE status = 1 ORDER BY id'
  const categories = await query(sql) as Category[]
  return categories
}

// 根据ID获取分类
export async function getCategoryById(id: number): Promise<Category | null> {
  const sql = 'SELECT * FROM blog_categories WHERE id = ? AND status = 1'
  const categories = await query(sql, [id]) as Category[]
  
  if (categories.length === 0) return null
  return categories[0]
} 